/*
 *  三维空间画布,提供"三维模型"渲染到"相机屏幕"的方法
 */
#ifndef _3D_CANVA_H_
#define _3D_CANVA_H_

#include "3d_model.h"
#include "3d_camera.h"
#include "image_format.h"

class D3Canva
{
public:
    //一张画布绑定一个相机
    D3Canva(D3Camera *camera);
    ~D3Canva();

    int32_t GetWidth();
    int32_t GetHeight();

    //获取屏幕缓冲
    Image GetImage();

    //清空画布
    void Clear(uint32_t color = 0xFF000000);

    //渲染模型
    void Draw(D3Model *models, int32_t num = 1);
    //渲染模型部件
    void DrawPart(D3ModelPart part);

private:
    int32_t width, height;
    D3Camera *camera;
    Image image;
    float **depthGrid; //二维深度表
    uint8_t **flagGrid; //二维标记表(用于渲染模型时,防止单个点反复绘制)
    uint8_t flagCurrent = 0; //标记表当前值

    //渲染直线
    void D2DrawLine(int32_t *xy, float *depth, uint32_t color);
    //渲染三角形(纯色填充)
    void D2DrawTriangle(int32_t *xy, float *depth, uint32_t color);
    //渲染三角形(图片填充)
    void D2DrawTriangle(int32_t *xy, float *depth, int32_t *xyToFilm, Film *film);
    //渲染矩形(纯色填充)
    void D2DrawRect(int32_t *xy, float *depth, uint32_t color);
    //渲染矩形(图片填充)
    void D2DrawRect(int32_t *xy, float *depth, Film *film);
};

#endif // _3D_CANVA_H_
